package com.burgeon.backend.Rest.Tags;
/**
 * 创建标签
 */

import com.burgeon.backend.Rest.base.RESTBase;
import com.burgeon.backend.entity.User;
import com.burgeon.backend.entity.VipAttrib;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.HashMap;

public class InsertVipTagsBos extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public InsertVipTagsBos(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     */

    public void getData(String phone, VipAttrib data) throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";

        String str = RESULT(Data(phone,data), url);
        System.err.println(str);
        String code = new JSONArray(str).getJSONObject(0).getString("code");

        if (!"0".equals(code)) {
            throw new Exception("创建失败");
        }
    }

    private MultiValueMap Data(String phone, VipAttrib data) {

        HashMap params = new HashMap();

        params.put("c_vip_id__cardno",phone);

        if (!data.getVipAttrib1().equals(" "))
        params.put("C_VIPATTRIB1_ID__NAME", "'"+data.getVipAttrib1()+"'");
        if (!data.getVipAttrib2().equals(" "))
        params.put("C_VIPATTRIB2_ID__NAME", "'"+data.getVipAttrib2()+"'");
        if (!data.getVipAttrib3().equals(" "))
        params.put("C_VIPATTRIB3_ID__NAME", "'"+data.getVipAttrib3()+"'");
        if (!data.getVipAttrib4().equals(" "))
        params.put("C_VIPATTRIB4_ID__NAME", "'"+data.getVipAttrib4()+"'");
        if (!data.getVipAttrib5().equals(" "))
        params.put("C_VIPATTRIB5_ID__NAME", "'"+data.getVipAttrib5()+"'");
        if (!data.getVipAttrib6().equals(" "))
        params.put("C_VIPATTRIB6_ID__NAME", "'"+data.getVipAttrib6()+"'");
        if (!data.getVipAttrib7().equals(" "))
        params.put("C_VIPATTRIB7_ID__NAME", "'"+data.getVipAttrib7()+"'");
        if (!data.getVipAttrib8().equals(" "))
        params.put("C_VIPATTRIB8_ID__NAME", "'"+data.getVipAttrib8()+"'");
        if (!data.getVipAttrib9().equals(" "))
        params.put("C_VIPATTRIB9_ID__NAME", "'"+data.getVipAttrib9()+"'");
        if (!data.getVipAttrib10().equals(" "))
        params.put("C_VIPATTRIB10_ID__NAME", "'"+data.getVipAttrib10()+"'");
        if (!data.getVipAttrib11().equals(" "))
        params.put("C_VIPATTRIB11_ID__NAME", "'"+data.getVipAttrib11()+"'");
        if (!data.getVipAttrib12().equals(" "))
        params.put("C_VIPATTRIB12_ID__NAME", "'"+data.getVipAttrib12()+"'");
        if (!data.getVipAttrib13().equals(" "))
        params.put("C_VIPATTRIB13_ID__NAME", "'"+data.getVipAttrib13()+"'");
        if (!data.getVipAttrib14().equals(" "))
        params.put("C_VIPATTRIB14_ID__NAME", "'"+data.getVipAttrib14()+"'");
        if (!data.getVipAttrib15().equals(" "))
        params.put("C_VIPATTRIB15_ID__NAME", "'"+data.getVipAttrib15()+"'");

        params.put("table", "C_VIPATTRIB");//表名

        return DATA("ObjectCreate", params, account, password);
    }

    public static void main(String[] args) {
        InsertVipTagsBos g = new InsertVipTagsBos("39.100.45.8:55322", "nea@burgeon.com.cn", "123");
        try {
            VipAttrib vipAttrib = new VipAttrib();
          //  vipAttrib.setVipAttrib2("120-140");
            g.getData("17732145129",vipAttrib);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
